// import {}
import { ErrorCode } from '../../../../../base/oh_modules/coremail/src/main/ets/api';

export class ErrorUtil {
  static codeToMsg(code: number): string {
    switch (code) {
      case ErrorCode.Error:
      case ErrorCode.UNKNOWN_ERROR:
        return "未知异常";
      case ErrorCode.CONNECT_TIMEOUT:
        return "连接服务器超时";
      case ErrorCode.LOGIN_FAILED:
        return "账号或密码错误";
      case ErrorCode.CONNECT_FAILED:
        return "连接服务器失败";
      case ErrorCode.PARAMETER_ERROR:
        return "参数错误";
      case ErrorCode.NOT_FOUND:
        return "邮件不存在";
      case ErrorCode.FOLDER_NOT_FOUND:
      case ErrorCode.FOLDER_EXISTS:
        return "邮件文件夹不存在";
      case ErrorCode.PARSE_MAIL_FAILED:
        return "解析邮件内容出错";
      case ErrorCode.NoAvailableNetwork:
        return "网络不可用";
      case ErrorCode.ServerUnReachable:
      case ErrorCode.ServerNotSupport:
        return "服务器连接异常";
      case ErrorCode.FolderNotFound:
        return "邮件文件夹不存在";
      case ErrorCode.CreateFolderFailed:
        return "创建文件夹失败";
      case ErrorCode.MailNotFound:
        return "邮件不存在";
      case ErrorCode.MailPartNotFound:
        return "解析邮件失败";
      case ErrorCode.MailAttributeNotFound:
      case ErrorCode.MailAttributeNotSupport:
      case ErrorCode.MailAttributeNotWritable:
        return "未知异常";
      case ErrorCode.SentMailFailed:
      case ErrorCode.PROTOCOL_ERROR:
        return "发信失败";
      default:
        return "未知异常";
    }
  }

  static getCodeErr(code: number, protocol: string): string {
    switch (code) {
      case ErrorCode.LOGIN_FAILED:
        return "账号或密码错误，请确认信息填写是否正确。";
      case ErrorCode.CONNECT_FAILED:
      case ErrorCode.CONNECT_TIMEOUT:
      case ErrorCode.UNKNOWN_ERROR:
        return `无法连接到${protocol.toUpperCase()}服务器，可能服务器或端口填写错误，请检查后重试。`;
      case ErrorCode.NoAvailableNetwork:
      default:
        return "网络异常，请检查网络后重试。";
    }
  }
}